---@diagnostic disable: unused-local
local extension = Package("freak_alliance_hermit")
extension.extensionName = "freak_alliance"

Fk:loadTranslationTable{
  ["freak_alliance"] = "怀异集", 
  ["freak_alliance_hermit"] = "怀异集·少微",
  ["fa"] = "怀异",
}

local H = require 'packages/hegemony/util'
local fa__yuji = General(extension, "fa__yuji", "qun", 3,3)

local fa__qiongguan = fk.CreateTriggerSkill{
  name = "fa__qiongguan",
  anim_type = "drawcard",
  events = {fk.CardShown},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self, true) then
    local ids = {}
    for _, id in ipairs(data.cardIds) do
      if Fk:getCardById(id).trueName == "slash" then
      table.insert(ids, id)
      end
    end
    return #ids > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    H.addHegMark(room, player, "vanguard")
  end,
}
local fa__qiongguan_show = fk.CreateTriggerSkill{
  name = "#fa__qiongguan_show",
  anim_type = "special",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card and
     (data.card.trueName == 'lure_tiger' or data.card.trueName == 'known_both')
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(TargetGroup:getRealTargets(data.tos), function (id)
      return not room:getPlayerById(id).dead end)
    if #targets == 1 then
      if room:askForSkillInvoke(player, self.name, nil, "#fa__qiongguan-invoke::" .. targets[1]) then
        room:doIndicate(player.id, targets)
        self.cost_data = targets
        return true
      end
    else
      targets = room:askForChoosePlayers(player, targets, 1, 1, "#fa__qiongguan-choose", self.name, true)
      if #targets > 0 then
        self.cost_data = targets
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data[1])
    player:showCards(to:getCardIds("h"))
  end,
}

local fa__fuxuan = fk.CreateTriggerSkill{
  name = "fa__fuxuan",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.Death},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self, false, true)
    and data.damage and data.damage.from and not data.damage.from:isNude()
  end,
  on_use = function(self, event, target, player, data)
    local from = data.damage.from
    local room = player.room
    room:setPlayerMark(from, "@@fa__fuxuan", 1)
    room:handleAddLoseSkills(from, "#fa__fuxuan_Clear", nil)
    if from.phase == from.NotActive then
      player:control(from)
    end
  end,
}
local fa__fuxuan_Trig = fk.CreateTriggerSkill{
  name = "#fa__fuxuan_Trig",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self, false, true) and
      target:getMark("@@fa__fuxuan") == 1
  end,
  on_cost = function() return true end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke("fa__fuxuan")
    player:control(target)
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function(_, _, target, player)
     return target == player and target:getMark("@@fa__fuxuan") == 1 and target.faceup
  end,
  on_refresh = function(_, _, target)
      target:control(target)
  end,
}
local fa__fuxuan_Clear = fk.CreateTriggerSkill{
  name = "#fa__fuxuan_Clear",
  events = {fk.Damaged},
  anim_type = "negative",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and target:getMark("@@fa__fuxuan") == 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
      player:broadcastSkillInvoke("fa__fuxuan")
      room:setPlayerMark(target, "@@fa__fuxuan", 0)
      target:control(target)
  end,
}

fa__qiongguan:addRelatedSkill(fa__qiongguan_show)
fa__yuji:addSkill(fa__qiongguan)
fa__fuxuan:addRelatedSkill(fa__fuxuan_Trig)
fa__fuxuan:addRelatedSkill(fa__fuxuan_Clear)
fa__yuji:addSkill(fa__fuxuan)


Fk:loadTranslationTable{
  ["fa__yuji"] = "于吉", 
  ["#fa__yuji"] = "精分白鹿",
  ["cv:fa__yuji"] = "天外之音",
  ["illustrator:fa__yuji"] = "未知",
  ["designer:fa__yuji"] = "幽蝶",

  ["fa__qiongguan"] = "穹观",
  [":fa__qiongguan"] = "你使用【知己知彼】或【调虎离山】后，可以展示一名目标角色的手牌。"..
  "一名角色展示包含【杀】的牌后，你可以获得一枚【先驱】。",
  ["#fa__qiongguan_show"] = "穹观",
  ["#fa__qiongguan-invoke"] = "是否对%dest发动 穹观，展示其手牌，若其中有【杀】你可以获得【先驱】",
  ["#fa__qiongguan-choose"] = "穹观：展示一名目标角色的手牌，若其中有【杀】你可以获得【先驱】",
  ["fa__fuxuan"] = "符玄",--蒸馍，想看彩蛋？不如自己去玩玩崩坏星（被捂嘴）没有崩坏的星董卓感受数值的强大吧！
  [":fa__fuxuan"] = "锁定技，你死亡时，获得伤害来源回合外的控制权，直至其受到伤害。",
  ["@@fa__fuxuan"] = "符玄之令 缠怨",
  ["#fa__fuxuan_Trig"] = "符玄",
  ["#fa__fuxuan_Clear"] = "符玄",

  ["$fa__qiongguan1"] = "目下所见，上苍所示，天机亦可穷观。",
  ["$fa__qiongguan2"] = "草兽喃喃，风雷猎猎，天机不语自明。",
  ["$fa__qiongguan3"] = "凶卦现世，魑魅并出，山林难为安身所，市井可作苦修庙...",
  ["$fa__qiongguan4"] = "乱世之兆昭然，乱离之苦怆然，此正代天宣化，普救黎庶之时。",
  ["$fa__fuxuan1"] = "以赤血画玄符，承三清之威能，惩暴戾之狂徒！",
  ["$fa__fuxuan2"] = "不恤待救草民，不敬施医仙师，不忠不仁不义，缠怨百死未止！",
  ["$fa__fuxuan3"] = "伯符我儿，何以忘老母之教诲，又杀江东名士也？",
  ["$fa__fuxuan4"] = "面如此知不可立世，奈滥行杀戮，坏乱大道者何？",
  ["~fa__yuji"] = "尔非不信鬼神，乃事杀伐而立淫威，天必不佑！",
}

return extension